package cn.net.xyan.yypt.dto

import com.fasterxml.jackson.annotation.JsonFormat
import com.fasterxml.jackson.annotation.JsonProperty
import java.math.BigDecimal
import java.util.*

const val InvokeSuccess = "10000"

const val WaitBuyerPay = "WAIT_BUYER_PAY"
const val TradeClosed = "TRADE_CLOSED"
const val TradeSuccess = "TRADE_SUCCESS"
const val TradeFinished = "TRADE_FINISHED"


class LinkingCloudResponse<T> {

    @JsonProperty("app_id")
    var appID: String? = null

    @JsonProperty("method")
    var method: String? = null

    @JsonProperty("timestamp")
    var timestamp: String? = null

    @JsonProperty("nonce_str")
    var nonceStr: String? = null

    @JsonProperty("code")
    var code: String? = null

    @JsonProperty("msg")
    var msg: String? = null

    @JsonProperty("sign_type")
    var signType: String? = null

    @JsonProperty("sign")
    var sign: String? = null

    @JsonProperty("biz_content")
    var bizContent: T? = null
}

class QRCodeRsp {

    @JsonProperty("sub_code")
    var subCode: String? = null

    @JsonProperty("sub_msg")
    var subMsg: String? = null

    @JsonProperty("out_trade_no")
    var outTradeNo: String? = null

    @JsonProperty("qr_code")
    var qrCode: String? = null
}

class BarCodeRsp {
    @JsonProperty("sub_code")
    var subCode: String? = null

    @JsonProperty("sub_msg")
    var subMsg: String? = null

    @JsonProperty("out_trade_no")
    var outTradeNo: String? = null

    @JsonProperty("trade_no")
    var tradeNo: String? = null

    @JsonProperty("total_amount")
    var totalAmount: BigDecimal? = null

    @JsonProperty("gmt_payment")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    var gmtPayment: Date? = null

    @JsonProperty("user_id")
    var userId: String? = null

    @JsonProperty("logon_id")
    var logonId: String? = null

    @JsonProperty("trade_status")
    var tradeStatus: String? = null

    @JsonProperty("payment_type")
    var paymentType: String? = null
}

class QueryOrderRsp {
    @JsonProperty("sub_code")
    var subCode: String? = null

    @JsonProperty("sub_msg")
    var subMsg: String? = null

    @JsonProperty("out_trade_no")
    var outTradeNo: String? = null

    @JsonProperty("trade_no")
    var tradeNo: String? = null

    @JsonProperty("total_amount")
    var totalAmount: BigDecimal? = null

    @JsonProperty("gmt_payment")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    var gmtPayment: Date? = null

    @JsonProperty("user_id")
    var userId: String? = null

    @JsonProperty("logon_id")
    var logonId: String? = null

    @JsonProperty("trade_status")
    var tradeStatus: String? = null

    @JsonProperty("payment_type")
    var paymentType: String? = null
}

class RefundOrderRsp {

    @JsonProperty("sub_code")
    var subCode: String? = null

    @JsonProperty("sub_msg")
    var subMsg: String? = null

    @JsonProperty("out_trade_no")
    var outTradeNo: String? = null

    @JsonProperty("trade_no")
    var tradeNo: String? = null

    @JsonProperty("refund_fee")
    var refundFee: BigDecimal? = null

    @JsonProperty("gmt_refund_pay")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    var gmtRefundPay: Date? = null

}

class QueryRefundRsp {

    @JsonProperty("sub_code")
    var subCode: String? = null

    @JsonProperty("sub_msg")
    var subMsg: String? = null

    @JsonProperty("out_trade_no")
    var outTradeNo: String? = null

    @JsonProperty("trade_no")
    var tradeNo: String? = null

    @JsonProperty("out_request_no")
    var outRequestNo: String? = null

    @JsonProperty("refund_amount")
    var refundAmount: BigDecimal? = null

}

class CallbackBizContentRsp {

    @JsonProperty("trade_no")
    var tradeNo: String? = null

    @JsonProperty("out_trade_no")
    var outTradeNo: String? = null

    @JsonProperty("user_id")
    var userId: String? = null

    @JsonProperty("trade_status")
    var tradeStatus: String? = null

    @JsonProperty("total_amount")
    var totalAmount: BigDecimal? = null

    val payVendor: String
        get() {
            val t = tradeNo ?: ""

            return when (t[0]) {
                '2' -> "alipay"
                '4' -> "weChat"
                else -> "unknown"
            }

        }
}
